package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.annotation.Anonymous;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.domain.OpenCooperation;
import com.blrs.service.open.IOpenCooperationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 开放合作Controller
 * 
 * @author xiaoyang
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/open/cooperation")
public class OpenCooperationController extends BaseController
{
    @Autowired
    private IOpenCooperationService openCooperationService;

    /**
     * 查询开放合作列表
     */
//    @PreAuthorize("@ss.hasPermi('open:cooperation:list')")
    @GetMapping("/list")
    public TableDataInfo list(OpenCooperation openCooperation)
    {
        startPage();
        openCooperation.setBelongTo(String.valueOf(SecurityUtils.getOrgId()));
        List<OpenCooperation> list = openCooperationService.selectOpenCooperationList(openCooperation);
        return getDataTable(list);
    }
    @GetMapping("/listOpen")
    @Anonymous
    public TableDataInfo listOpen(OpenCooperation openCooperation)
    {
        startPage();
        List<OpenCooperation> list = openCooperationService.selectOpenCooperationList(openCooperation);
        return getDataTable(list);
    }

    /**
     * 导出开放合作列表
     */
//    @PreAuthorize("@ss.hasPermi('open:cooperation:export')")
    @Log(title = "开放合作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OpenCooperation openCooperation)
    {
        List<OpenCooperation> list = openCooperationService.selectOpenCooperationList(openCooperation);
        ExcelUtil<OpenCooperation> util = new ExcelUtil<OpenCooperation>(OpenCooperation.class);
        util.exportExcel(response, list, "开放合作数据");
    }

    /**
     * 获取开放合作详细信息
     */
//    @PreAuthorize("@ss.hasPermi('open:cooperation:query')")
    @GetMapping(value = "/{id}")
    @Anonymous
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(openCooperationService.selectOpenCooperationById(id));
    }

    /**
     * 新增开放合作
     */
//    @PreAuthorize("@ss.hasPermi('open:cooperation:add')")
    @Log(title = "开放合作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OpenCooperation openCooperation)
    {
        return toAjax(openCooperationService.insertOpenCooperation(openCooperation));
    }

    /**
     * 修改开放合作
     */
//    @PreAuthorize("@ss.hasPermi('open:cooperation:edit')")
    @Log(title = "开放合作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OpenCooperation openCooperation)
    {
        return toAjax(openCooperationService.updateOpenCooperation(openCooperation));
    }

    /**
     * 删除开放合作
     */
//    @PreAuthorize("@ss.hasPermi('open:cooperation:remove')")
    @Log(title = "开放合作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(openCooperationService.deleteOpenCooperationByIds(ids));
    }
}
